package com.crk.util;

import java.util.List;


/**
 * @author Administrator
 * @DESCRIPTION 统一API响应结果封装
 */
public class RestResult<T> {
    private int code;//状态码,0-成功；1-失败

    private String msg;//消息

    private List<T> data;//数据
    
    private T obj; //对象
    
    private long count; //记录数量

    public static <T> RestResult<T> ok(){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg("成功");
    	return result;
    }
    
    public static <T> RestResult<T> ok(String msg){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg(msg);
    	return result;
    }
    
    public static <T> RestResult<T> ok(T obj){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg("成功");
    	result.setObj(obj);
    	return result;
    }
    
    public static <T> RestResult<T> ok(T obj,String msg){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg(msg);
    	result.setObj(obj);
    	return result;
    }
    
    public static <T> RestResult<T> ok(List<T> data){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg("成功");
    	result.setData(data);
    	return result;
    }
    
    public static <T> RestResult<T> ok(List<T> data,String msg){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(0);
    	result.setMsg(msg);
    	result.setData(data);
    	return result;
    }
    
    public static <T> RestResult<T> failed(String msg){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(1);
    	result.setMsg(msg==null?"失败":msg);
    	return result;
    }
    
    public static <T> RestResult<T> failed(int code, String msg){
    	RestResult<T> result= new RestResult<>();
    	result.setCode(code);
    	result.setMsg(msg==null?"失败":msg);
    	return result;
    }
    
    
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public T getObj() {
		return obj;
	}

	public void setObj(T obj) {
		this.obj = obj;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}
}

